Imports GeoFramework

Public Class StringParsingForm

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Call the textbox events to make them display formatted values
        AngleTextBox_TextChanged(Me, EventArgs.Empty)
        AzimuthTextBox_TextChanged(Me, EventArgs.Empty)
        DistanceTextBox_TextChanged(Me, EventArgs.Empty)
        SpeedTextBox_TextChanged(Me, EventArgs.Empty)
        LatitudeTextBox_TextChanged(Me, EventArgs.Empty)
        LongitudeTextBox_TextChanged(Me, EventArgs.Empty)
        PositionTextBox_TextChanged(Me, EventArgs.Empty)

    End Sub

    Private Sub AngleTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles AngleTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Angle = Angle.Parse(AngleTextBox.Text)
            ' And format it  ("h" for hours, "m" for minutes, "s" for seconds)
            ParsedAngle.Text = Result.ToString(AngleFormat.Text)
        Catch
            ParsedAngle.Text = "(Unknown)"
        End Try
    End Sub

    Private Sub AzimuthTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles AzimuthTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Azimuth = Azimuth.Parse(AzimuthTextBox.Text)
            ' And format it  ("h" for hours, "m" for minutes, "s" for seconds, 
            ' and "c" or "cc" for compass direction.
            ParsedAzimuth.Text = Result.ToString(AzimuthFormat.Text)
        Catch
            ParsedAzimuth.Text = "(Unknown)"
        End Try
    End Sub

    Private Sub DistanceTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DistanceTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Distance = Distance.Parse(DistanceTextBox.Text)
            ' And format it (v for "value", u for "units")
            ParsedDistance.Text = Result.ToString(DistanceFormat.Text)
        Catch
            ParsedDistance.Text = "(Unknown)"
        End Try
    End Sub

    Private Sub SpeedTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SpeedTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Speed = Speed.Parse(SpeedTextBox.Text)
            ' And format it (v for "value", u for "units")
            ParsedSpeed.Text = Result.ToString(SpeedFormat.Text)
        Catch
            ParsedSpeed.Text = "(Unknown)"
        End Try
    End Sub

    Private Sub LatitudeTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles LatitudeTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Latitude = Latitude.Parse(LatitudeTextBox.Text)
            ' And format it (v for "value", u for "units")
            ParsedLatitude.Text = Result.ToString(LatitudeFormat.Text)
        Catch
            ParsedLatitude.Text = "(Unknown)"
        End Try
    End Sub

    Private Sub LongitudeTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles LongitudeTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Longitude = Longitude.Parse(LongitudeTextBox.Text)
            ' And format it (v for "value", u for "units")
            ParsedLongitude.Text = Result.ToString(LongitudeFormat.Text)
        Catch
            ParsedLongitude.Text = "(Unknown)"
        End Try
    End Sub

    Private Sub PositionTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles PositionTextBox.TextChanged
        Try
            ' Convert the string into an angle object
            Dim Result As Position = Position.Parse(PositionTextBox.Text)
            ' And format it (v for "value", u for "units")
            ParsedPosition.Text = Result.ToString(PositionFormat.Text)
        Catch
            ParsedPosition.Text = "(Unknown)"
        End Try
    End Sub
End Class